package com.taijihuabao.modules.controller;

import com.taijihuabao.common.jsonresult.JsonResult;
import com.taijihuabao.modules.entity.BaseClockEntity;
import com.taijihuabao.modules.entity.BaseTypeEntity;
import com.taijihuabao.modules.entity.ExpenseEntity;
import com.taijihuabao.modules.model.baseclock.vo.BaseTypeVO;
import com.taijihuabao.modules.service.BaseClockService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @title: BaseClockController
 * @Author luoxianan
 * @Date: 2022/1/7 11:10
 * @Version 1.0
 */
@Api(tags = "码表管理")
@RestController
@RequestMapping("/api/v1/baseClock")
public class BaseClockController {
    @Autowired
    private BaseClockService baseClockService;

    @ApiOperation("根据码表类型查询")
    @PostMapping("/selectByTypeName")
    public JsonResult selectByTypeName(@RequestBody BaseTypeVO baseTypeVO){
        BaseTypeVO baseTypeVO1 = baseClockService.selectByTypeName(baseTypeVO.getTypeName());
        return JsonResult.success(baseTypeVO1);
    }

    @ApiOperation("增加码表类型")
    @PostMapping("/insertBaseType")
    public JsonResult insertBaseType(@RequestBody BaseTypeEntity baseTypeEntity){
        BaseTypeEntity baseTypeEntity1 = baseClockService.insertBaseType(baseTypeEntity);
        return JsonResult.success(baseTypeEntity1);
    }

    @ApiOperation("根据码表类型的ID查询码值")
    @PostMapping("/selectAllByTypeId")
    public JsonResult selectAllByTypeId(@RequestBody BaseClockEntity baseClockEntity){
        List<BaseClockEntity> baseClockEntities = baseClockService.selectAllByTypeId(baseClockEntity.getTypeId());
        return JsonResult.success(baseClockEntities);
    }

    @ApiOperation("根据码表类型修改码值")
    @PostMapping("/updateByTypeId")
    public JsonResult updateByTypeId(@RequestBody BaseClockEntity baseClockEntity){
        baseClockService.updateByTypeId(baseClockEntity);
        return JsonResult.success();
    }

    @ApiOperation("增加码值")
    @PostMapping("/insertAll")
    public JsonResult insertAll(@RequestBody BaseClockEntity baseClockEntity){
        baseClockService.insertAll(baseClockEntity);
        return JsonResult.success();
    }
}
